﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BLL.ClientManage;
using System.Data;
using Common;
using Model.ClientManage;

namespace Web.Controllers
{
    public class ContractImgController : BaseController
    {
        T_tb_ContractImg tContractImg = new T_tb_ContractImg(); //电子杂志管理
        //
        // GET: /Laboratory/

        public ActionResult ContractImgList()
        {
            return View();
        }

        /// <summary>
        /// 获取所有数据列表
        /// 作者：小朱
        /// </summary>
        /// <returns>将DataTable转换为Json数据格式通过string类型返回</returns>
        public string GetList(int pageNumber, int pageSize, string StrSearch)
        {
            DataTable dt = new DataTable();
            int total = 0;
            string strWhere = "";
            if (!string.IsNullOrEmpty(StrSearch))
            {
                strWhere = PageTools.AddWhere(strWhere, "Title like '%" + StrSearch + "%' ");
            }

            try
            {
                dt = tContractImg.GetListByPage(strWhere, "AddTime Desc", pageNumber * pageSize - (pageSize - 1), pageNumber * pageSize, ref total).Tables[0];
            }
            catch { }
            string strJson = PublicClass.ToJson(dt, total);
            if (strJson.Trim() == "")
            {
                strJson = "{\"total\":0,\"rows\":[]}";
            }
            return strJson;
        }

        /// <summary>
        /// 显示详情页
        /// </summary>
        /// <param name="EditType">编辑类型</param>
        /// <returns>返回编辑结果</returns>
        public ActionResult ContractImgEdit(E_tb_ContractImg eContractImg, string EditType, int? InfoID)
        {
            if (EditType == "Edit")
            {
                eContractImg = tContractImg.GetModel(Convert.ToInt32(InfoID));
            }
            eContractImg.EditType = EditType;
            return View(eContractImg);
        }


        /// <summary>
        /// 保存实验室信息
        /// 作者：小朱
        /// </summary>
        /// <param name="eElectronicsMagazine">要处理的对象</param>
        /// <returns>返回是否处理成功</returns>
        [ValidateInput(false)]
        public string Save(E_tb_ContractImg eContractImg)
        {
            string msg = "0";
            eContractImg.AddTime = DateTime.Now;
            if (eContractImg.EditType == "Add")
            {
                tContractImg.Add(eContractImg);
                msg = "1";
            }
            else
            {
                tContractImg.Update(eContractImg);
                msg = "1";
            }
            return msg;
        }

        /// <summary>
        /// 删除实验室信息
        /// 作者：小朱
        /// </summary>
        /// <param name="InfoID">要删除的实验室</param>
        /// <returns>返回是否删除成功</returns>
        public JsonResult Delete(int id)
        {
            string str = (tContractImg.Delete(id)) ? "删除成功！" : "删除失败！";
            return Json(str, JsonRequestBehavior.AllowGet);
        }

    }
}
